<?php

namespace App\Http\Controllers;

use EasyWeChat\Factory;
use Illuminate\Support\Facades\Http;


class TestController extends Controller
{
    public function send()
    {
        $tplId = 'o6tSsxp_cyVeuVc-Dpl4lncstpHbA-dcjA36ycuE4xM';
        $req = [
            'touser'      => 'o7tUYs6mBNLBl9Vtl0hVxZyv8fYo',
            'template_id' => $tplId,
            //'url'         => 'http://baoming.xywlk.com/gprssearch.aspx?openid=ou00Qs4HW5q_2Sz6VO9zxoudDCVg',
            'data'        => [
                'thing2' => '一手app',
                'const5' => '佣金结算',
                'time4'  => date('Y-m-d H:i:s'),
            ],
        ];
        $config = config('wechat.offical');
        $app = Factory::officialAccount($config);
        $accessToken = $app->access_token->getToken();
        $url = 'https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token=' . $accessToken['access_token'];
        $result = Http::asJson()->post($url, ['offset' => 0, 'count' => 20])->json();
        return response()->json([
            'result'       => $result,
            'access_token' => $accessToken,
        ]);
        var_dump($accessToken);
        die;
        $res = $app->template_message->send($req);
        var_dump($res);
    }
}
